package org.travel_system.mapper;

import org.apache.ibatis.annotations.*;
import org.travel_system.pojo.Hotel;
import org.travel_system.pojo.Room;

import java.util.List;

@Mapper
public interface HotelMapper {
    //查询酒店列表
    @Select("select * from hotel")
    List<Hotel> getHotels();

    @Select("SELECT * FROM hotel ORDER BY popularity  LIMIT 4")
    List<Hotel> getHotelsImage();

    //根据名称查询
    @Select("select * from hotel where hotel_name=#{name}")
    Hotel getHotelByName(String name);

    //删除酒店
    @Delete("delete from hotel where hotel_name=#{name}")
    int deleteHotel(String name);

    //更新酒店
    @Update("update hotel set is_stared=#{isStared},popularity=#{popularity} where hotel_name=#{hotelName}")
    int updateHotel(Hotel hotel);

    //添加酒店
    @Insert("insert into hotel(hotel_name, is_stared, popularity,image,email,phone_number,location,description)" +
            " values (#{hotelName},#{isStared},#{popularity},#{Image},#{email},#{phoneNumber},#{location},#{description})")
    int addHotel(Hotel hotel);

    //获取酒店房间信息
    @Select("select * from room where hotel_name=#{hotelName}")
    List<Room> getRooms(String hotelName);

    //根据房间编号查询
    @Select("select * from room where hotel_name=#{hotelName} and room_number=#{roomNumber}")
    Room getRoomByRoomNumber(String hotelName, int roomNumber);

    //添加房间数
    @Insert("insert into room(room_number, hotel_name, is_booked)" +
            "values (#{roomNumber},#{hotelName},#{isBooked})")
    int addRoom(Room room);

    //删除房间
    @Delete("delete from room where room_number=#{roomNumber} and hotel_name=#{hotelName}")
    int deleteRoom(String hotelName, String roomNumber);

    //更新房间的信息
    @Update("update room set is_booked=#{isBooked} where room_number=#{roomNumber} and hotel_name=#{hotelName}")
    int updateRoom(Room room);

    //获取所有房间信息
    @Select("select * from room")
    List<Room> getAllRooms();

    //实现模糊查询
    @Select("SELECT * FROM hotel WHERE hotel_name LIKE CONCAT('%', #{name}, '%')")
    List<Hotel> getHotelsByName(@Param("name") String name);
}
